import Cookie from 'js-cookie'
import { apigetUserInfo } from '../api'
import Store from '../store';


export const getCookie = (cookieName = 'token') => {
    return Cookie.get(cookieName)
}

// 获取用户信息
export const  getUserInfo = () => {
    // 判断token 是否
    if(getCookie()) {
        apigetUserInfo().then(res => {
            Store.dispatch({type: 'CHANGE_USER_INFO', data: res.data})            

        }).catch(() => {
            // 删除本地存储
            Cookie.remove('token')

            // 跳转到登录页面
            window.location.href = '/login'
        })
    }
}